package api;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;

/**
 * 字符编码转换
 * https://kylepeng93.github.io
 *
 * @author pengkai
 * @date 2021-03-22 下午11:16
 */
public class CharsetTransfer {
    @Test
    public void toGbk() {
        String str = "中国";
        try {
            System.out.println(str.getBytes("GB18030").length);
            System.out.println(str.getBytes().length);
            System.getProperties().forEach((key, value) -> {
                if (StringUtils.indexOfIgnoreCase((String)key, "java") >= 0) {
                    System.out.println(MessageFormat.format("{0} = {1}", key,value));
                }
            });
            System.getenv().forEach((key,value) -> {
//                System.out.println(MessageFormat.format("{0} = {1}", key, value));
            });
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

}
